package WordCount;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class DriTest {
    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();

        Job job = Job.getInstance(conf);
        job.setJarByClass(DriTest.class);
        job.setMapperClass(MapTest.class);
        job.setReducerClass(RedTest.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        job.setCombinerClass(RedTest.class);

        FileInputFormat.setInputPaths(job, "D:\\MP\\WordCount\\input");
        Path path = new Path("D:\\MP\\WordCount\\output");
        if (path.getFileSystem(conf).exists(path)) {
            path.getFileSystem(conf).delete(path, true);
        }
        FileOutputFormat.setOutputPath(job,path);

        boolean b = job.waitForCompletion(true);
        System.exit(b ? 0 : 1);
    }
}
